
class FryingPan extends FFWeapon;

#exec MESH IMPORT MESH=FryingPanAnimated ANIVFILE=MODELS\FryingPanAnimated_a.3d DATAFILE=MODELS\FryingPanAnimated_d.3d X=0 Y=0 Z=0 UNMIRROR=1
//#exec MESH ORIGIN MESH=FryingPanAnimated X=0 Y=0 Z=0 PITCH=-10 ROLL=10 YAW=-128    //Other hand (original)
#exec MESH ORIGIN MESH=FryingPanAnimated X=0 Y=0 Z=0 PITCH=-10 ROLL=10 YAW=0

#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=All STARTFRAME=0 NUMFRAMES=72
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Still STARTFRAME=1 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=PrimaryAttack STARTFRAME=2 NUMFRAMES=17
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryAttackStart STARTFRAME=19 NUMFRAMES=3
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryCharge STARTFRAME=22 NUMFRAMES=24
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=SecondaryRelease STARTFRAME=46 NUMFRAMES=10
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Select STARTFRAME=61 NUMFRAMES=6
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Deselect STARTFRAME=67 NUMFRAMES=5
#exec MESH SEQUENCE MESH=FryingPanAnimated SEQ=Down STARTFRAME=67 NUMFRAMES=5

#exec MESHMAP NEW MESHMAP=FryingPanAnimated MESH=FryingPanAnimated
#exec MESHMAP SCALE MESHMAP=FryingPanAnimated X=0.1 Y=0.1 Z=0.2

#exec TEXTURE IMPORT NAME=SimpleGloveHandTexture FILE=Textures/SimpleGloveHandTexture.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=SimpleGloveHandTexture FILE=Textures/SimpleGloveHandTexture.pcx GROUP=Skins PALETTE=SimpleGloveHandTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanAnimated NUM=1 TEXTURE=SimpleGloveHandTexture

#exec TEXTURE IMPORT NAME=FPTexture FILE=FPTexture.bmp GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=FPTexture FILE=FPTexture.bmp GROUP=Skins PALETTE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanAnimated NUM=2 TEXTURE=FPTexture

// Pickup
#exec MESH IMPORT MESH=FryingPanPickup ANIVFILE=MODELS\FryingPanPickup_a.3d DATAFILE=MODELS\FryingPanPickup_d.3d X=0 Y=0 Z=0
#exec MESH ORIGIN MESH=FryingPanPickup X=0 Y=700 Z=-50 PITCH=0 ROLL=64 YAW=0

#exec MESH SEQUENCE MESH=FryingPanPickup SEQ=All STARTFRAME=0 NUMFRAMES=1
#exec MESH SEQUENCE MESH=FryingPanPickup SEQ=Still STARTFRAME=0 NUMFRAMES=1

#exec MESHMAP NEW MESHMAP=FryingPanPickup MESH=FryingPanPickup
#exec MESHMAP SCALE MESHMAP=FryingPanPickup X=0.05 Y=0.05 Z=0.1

#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.pcx GROUP=Skins FLAGS=2
#exec TEXTURE IMPORT NAME=FPTexture FILE=Textures/FPTexture.pcx GROUP=Skins PALETTE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=1 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=2 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=3 TEXTURE=FPTexture
#exec MESHMAP SETTEXTURE MESHMAP=FryingPanPickup NUM=4 TEXTURE=FPTexture

//Sounds 
#exec AUDIO IMPORT FILE="Sounds\Bong1.Wav" NAME=Bong1 GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Gong1.Wav" NAME=Gong1 GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Swoosh.Wav" NAME=Swoosh GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\Swoosh1.Wav" NAME=Swoosh1 GROUP="Pan"
#exec AUDIO IMPORT FILE="Sounds\PanSplat.Wav" NAME=PanSplat GROUP="Pan"

#exec TEXTURE IMPORT NAME=FPanIcon FILE=Textures/FPanIcon.BMP GROUP="Icons" MIPS=OFF

var sound Swing, Swing1, Bong;
var bool bselected;
var PlayerPawn LastHit;

replication
{
    reliable if (Role == ROLE_Authority)
        PlayPrimaryAttack;
}

// No crosshairs
simulated function PostRender(canvas Canvas)
{
   Super.PostRender(Canvas);
   bOwnsCrossHair = bSelected;
   if (bOwnsCrossHair)
   {
      Canvas.SetPos(0.5 * Canvas.ClipX - 8, 0.5 * Canvas.ClipY - 8);
      Canvas.Style = 2;
      Canvas.Style = 1;
   }
}

function float RateSelf(out int bUseAltMode)
{
   local float EnemyDist;
   local bool bRetreating;
   local vector EnemyDir;

   bUseAltMode = 0;

   if ((Pawn(Owner) == None) || (Pawn(Owner).Enemy == None))
      return 0;

   EnemyDist = VSize(Pawn(Owner).Enemy.Location - Owner.Location);
   if (EnemyDist > 400)
      return -2;

   if (EnemyDist < 110)
      bUseAltMode = 0;

   return (FMin(1.0, 81/(EnemyDist + 1)));
}

function setHand(float Hand)
{
   local rotator newRot;

   Super.SetHand(Hand);
   if ( Hand == 1 ) 
      Mesh = mesh'FryingPanAnimated';
   else
 		Mesh = mesh'FryingPanAnimated';

}

function Fire(float value)
{
	GotoState('NormalFire');
}

function AltFire(float value) 
{
	GoToState('AltFiring');
}

state NormalFire
{
	function Beginstate()
   {
      local vector X,Y,Z, dir, HitLocation, backforce;
      local actor E;
      local float viewangle, blockangle;

		viewangle=cos(PI*150/360);
		blockangle=cos(PI*100/360);
      GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);

      foreach RadiusActors(class'Actor', E, 100, Owner.Location)
      {
      	dir=E.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
         	HitLocation = E.Location - normal(dir) * E.CollisionRadius;

            if (E.IsA('PlayerPawn') || E.IsA('Bot') || E.IsA('Decoration'))
            {
               E.TakeDamage(40.0, Pawn(Owner), HitLocation, 6000.0 * X, 'cut');
	       		PlaySound(sound'Gong1', SLOT_None, 150);
	       		spawn(class'SpriteSmokePuff',,,HitLocation);
            }
            else if (E.IsA('Carcass'))
            {
               PlaySound(sound'PanSplat', SLOT_None, 150);
               E.TakeDamage(100, Pawn(Owner), HitLocation, 3000.0*X, 'gibbed');
            }
         }
      }
   }
   
   function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }

Begin:
   PlayAnim('PrimaryAttack',1.0);
   Owner.PlaySound(Swing, SLOT_None,1.0*Pawn(Owner).SoundDampening);
   FinishAnim();
   GotoState('Idle');
}

state AltFiring
{
   function BeginState()
   {
   	local vector X,Y,Z, dir, HitLocation, backforce;
      local actor E;
      local float viewangle;

      viewangle=cos(PI*150/360);
      GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);

      playanim('SecondaryRelease',0.5);
      Owner.PlaySound(Swing1, SLOT_None,1.0*Pawn(Owner).SoundDampening);

      foreach RadiusActors(class'Actor', E, 100, Owner.Location)
      {
         dir=E.Location-Owner.Location;

         if((normal(dir) DOT normal(X)) > viewangle)
         {
            if ( E.IsA('PlayerPawn') || E.IsA('Bot') || E.IsA('Decoration'))
            {
               E.TakeDamage(40.0, Pawn(Owner), HitLocation, 100000.0 * X, 'cut');
	       		PlaySound(sound'Gong1', SLOT_None, 150);
	       		spawn(class'SpriteSmokePuff',,,HitLocation);
            }
            else if ( E.IsA('Carcass') )
            {
               PlaySound(sound'PanSplat', SLOT_None, 150);
               E.TakeDamage(100, Pawn(Owner), HitLocation, 3000.0*X, 'gibbed');
            }
         }
      }
   }
   
   function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bAltFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }

Begin:
   finishanim();
   GotoState('Idle');
}

simulated function PlayFiring()
{
	PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	if ( PlayerPawn(Owner) != None )
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	PlayAnim('PrimaryAttack',1.0);
}

simulated function PlayAltFiring()
{
   PlayOwnedSound(FireSound, SLOT_None, Pawn(Owner).SoundDampening*3.0);
	if ( PlayerPawn(Owner) != None )
		PlayerPawn(Owner).ShakeView(ShakeTime, ShakeMag, ShakeVert);
	playanim('SecondaryRelease',0.5);
}

state ClientFiring
{
   simulated function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }
}

state ClientAltFiring
{
   simulated function AnimEnd()
   {
      if (Pawn(Owner) != None && Pawn(Owner).bAltFire != 0)
         TweenAnim('Still', 0.1);
      else
         Super.AnimEnd();
   }
}

state Idle
{
	function tick(float dtime)
	{
		local projectile incoming;
		local pawn E;
		local vector dir,X,Y,Z;
		local float viewangle;
		local bool bDeflected;
		viewangle=cos(PI*150/360);
		GetAxes(Pawn(Owner).ViewRotation,X,Y,Z);
		bDeflected = false;
		
		if(pawn(owner).bFire == 0) 
		{
			foreach radiusactors(class'projectile',incoming,150)
			{
				if(incoming.IsA('Chunk') || incoming.IsA('Fragment') || incoming.IsA('ShellCase') || incoming.IsA('FFProjectileDeco') || incoming.IsA('Mtracer'))
					return;
				if(incoming.speed < 10)
					return;
				dir=incoming.location-location;
				if((normal(dir) DOT normal(X)) > viewangle)
				{
					PlayAnim('PrimaryAttack',2.0);
					PlayPrimaryAttack();
					Owner.PlaySound(sound'Bong1', SLOT_None,2.0*Pawn(Owner).SoundDampening);
					incoming.Destroy();
					Spawn(class'ut_SpriteSmokePuff',,,location);
					bDeflected = True;
					ClientFire(1);
				}
			}
		}
		if(pawn(owner).IsA('bot'))
		{
			if(bDeflected == false) 
			{
				foreach radiusactors(class'projectile',incoming,150) 
				{
					if(incoming.IsA('Chunk') || incoming.IsA('Fragment') || incoming.IsA('ShellCase') || incoming.IsA('DispersionAmmo') || incoming.IsA('BioGel'))
						return;
					if(incoming.speed < 10)
						return;
               incoming.Destroy();
					Spawn(class'ut_SpriteSmokePuff',,,location);
				}
			}
		}
	}
	function AnimEnd()
	{
		PlayIdleAnim();
	}
	function bool PutDown()
	{
		GotoState('DownWeapon');
		return True;
	}

Begin:
	SetTimer(2.5,True);
	if ( /*bFireMem ||*/ Pawn(Owner).bFire!=0 ) Global.Fire(0.0);
	if ( /*bAltFireMem ||*/ Pawn(Owner).bAltFire!=0 ) Global.AltFire(0.0);
	LoopAnim('Still');
}

simulated function PlayPrimaryAttack()
{
    if (Level.NetMode != NM_StandAlone)
        PlayAnim('PrimaryAttack',2.0);
}

defaultproperties
{
   Swing=Sound'Swoosh'
   Swing1=Sound'Swoosh1'
   Bong=Sound'Bong1'
   bMeleeWeapon=True
   AIRating=0.50
   AltRefireRate=0.00
   Icon=Texture'FPanIcon'
   StatusIcon=Texture'FPanIcon'
	bCanThrow=False
   PickupMessage="You found a Frying Pan!"
   ItemName="Frying Pan"
   ItemArticle="a"
   PlayerViewOffset=(X=10.00,Y=-2.00,Z=-4.00),
   PlayerViewMesh=LodMesh'FryingPanAnimated'
   PlayerViewScale=0.20
   PickupViewMesh=LodMesh'FryingPanPickup'
   ThirdPersonMesh=LodMesh'FryingPanPickup'
   ThirdPersonScale=0.50
   MaxDesireability=0.80
   Mesh=LodMesh'FryingPanPickup'
   SoundVolume=96
   CollisionRadius=15.00
   CollisionHeight=15.00
   InventoryGroup=1
}
